#pragma once
#include <iostream>
using namespace std;
namespace RO
{
	template<class T>
	class unique_ptr
	{
	public:
		unique_ptr() = default;

		explicit unique_ptr(T* ptr)
			:_ptr(ptr)
		{}

		unique_ptr(const unique_ptr& up) = delete;
		unique_ptr& operator=(unique_ptr& up) = delete;

		unique_ptr(unique_ptr&& up) noexcept
			:_ptr(up._ptr)
		{
			up._ptr = nullptr;
		}

		unique_ptr& operator=(unique_ptr&& up) noexcept
		{
			if (this != &up)
			{
				if (_ptr) delete _ptr;
				_ptr = up._ptr;
				up._ptr = nullptr;
			}

			return *this;
		}

		~unique_ptr()
		{
			if (_ptr)
			{
				cout << "delete:" << _ptr << endl;
				delete _ptr;
				_ptr = nullptr;
			}
		}

		T& operator*()
		{
			return *_ptr;
		}

		T* operator->()
		{
			return _ptr;
		}

	private:
		T* _ptr;
	};
}